<?php

function url($text) {
	if (FS_TYPE == 2) {
		$text = "/$text";
	}
	return $text;
}

function raw_json_encode($input) {

	return preg_replace_callback(
			'/\\\\u([0-9a-zA-Z]{4})/',
			function ($matches) {
				return mb_convert_encoding(pack('H*',$matches[1]),'UTF-8','UTF-16');
			},
			json_encode($input)
	);

}


function getIpLocationInfo($ip_address) {
	$json = http_get("http://ipinfo.io/$ip_address/json");
	return json_decode($json);
}


function getLocation($cad, $country) {
	$url = "http://api.geonames.org/search";
	$params = "q=$cad&name_startsWith=$cad&fuzzy=4&maxRows=10&username=xionjames&cities=cities1000&";
	$params .= "country=$country&featureClass=P&type=json&style=FULL&lang=en";

	$json = http_get("$url?$params");
	return json_decode($json);
}

?>